﻿//PropDelegate.h

#ifndef PROP_DELEGATE_H
#define PROP_DELEGATE_H

#pragma once

#include <QStyleOptionViewItem>
#include <QWidget>
#include <QItemDelegate>
#include <QModelIndex>
#include <QAbstractItemModel>
#include "mytabledata.h"

class MenuInfo;
class PropDelegate : public QItemDelegate
{
	Q_OBJECT
public:
	PropDelegate(MyTableData *pTableData, QObject *parent = 0);
	~PropDelegate(void);

public:
	// 当双击表格里的某一个元素时，会调用这个函数，创造一个Editor
	QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;

	// 用于把模型的数据传递给代理类的控件
	void setEditorData(QWidget *editor, const QModelIndex &index) const;
	// 用于提交修改的数据
	void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;

	void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;

protected:
	//设置相关记录同一字段内容
	void SetSibRecordColumn(QAbstractItemModel *model, const QModelIndex &OldIndex, int SibRowNo, int FieldNo, QString ItemText, QVariant ItemData) const;
signals:
	void Signal_UserDataChang(int RowNo, bool bReInitFlag) const;

private:
	MyTableData		*m_pTableData;
	MenuInfo	    *m_pMenuInfo;
};

#endif
